package com.gitee.deament.server.core.cli;

import com.gitee.deament.server.config.SystemConfig;
import com.gitee.deament.server.core.annotation.CliHander;
import com.gitee.deament.server.core.data.ConnectData;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;


import java.util.List;

/**
 * 用户认证
 */
@CliHander(command="AUTH")
public class AUTHcli extends AbstractCli {


    @Override
    public void executeCli(ChannelHandlerContext channelHandlerContext,String command) {
        List<String> values= getValues(command);
        if(values.size()==1){
            channelHandlerContext.channel().writeAndFlush(new TextWebSocketFrame("\"ERR invalid password\""));
            return ;
        }
        String password=values.get(1);
        String channelId=channelHandlerContext.channel().id().asLongText();
        if(password.equals(SystemConfig.SYSTEM_PROPERTIES.getPassword())){
            ConnectData.USER_STORAGE.authBind(channelId);
            channelHandlerContext.channel().writeAndFlush(new TextWebSocketFrame("\"OK\""));
            return ;
        }
        channelHandlerContext.channel().writeAndFlush(new TextWebSocketFrame("\"ERR invalid password\""));

    }
    @Override
    public boolean checkIsLogin(){
        return false;
    }





}
